﻿/**********************************************************************
 * @file   SEASubSysGenerateMeshDialog.h
 * @brief  SEA子系统网格生成
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date   2025-01-15
 *********************************************************************/
#ifndef _SEASubSysGenerateMeshDialog_H
#define _SEASubSysGenerateMeshDialog_H

#include "GUISubSystemDialogAPI.h"
#include "GUIWidget/GUIDialogBase.h"

#include "FITK_Kernel/FITKCore/FITKThreadTask.h"

#include <QList>

namespace Ui
{
    class AutoGeneratedDialog;
}

namespace Core
{
    class FITKActionOperator;
}

namespace Interface
{
    class FITKUnstructuredMesh;
    class FITKComponentManager;
}

namespace Acoustics
{
    class FITKAbstractSEASubSys;
}

namespace GUI
{
    /**
     * @brief SEASubSysGenerateMeshDialog widget
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-10-23
     */
    class GUISubSystemDialogAPI SEASubSysGenerateMeshDialog : public GUIDialogBase
    {
        Q_OBJECT;
    public:
        /**
         * @brief creat constructor
         * @param[i]  obj            My Param doc
         * @param[i]  oper           operator
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-10-23
         */
        SEASubSysGenerateMeshDialog(Core::FITKActionOperator* oper, QWidget* parent = nullptr);
        /**
         * @brief Destroy object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-10-23
         */
        virtual ~SEASubSysGenerateMeshDialog();

        /**
         * @brief    设置网格数据
         * @param[i] meshObj 
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-12-26
         */
        void setMeshData(Interface::FITKUnstructuredMesh* meshObj);
        /**
         * @brief    网格生成
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-12-26
         */
        bool startMeshGen();

    protected slots:
        /**
         * @brief    gmsh生成
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-12-26
         */
        bool meshGenGmsh();
        /**
         * @brief  网格文件读取
         * @return   bool
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-11-18
         */
        bool mshFileReader();

    protected:

        /**
         * @brief    SEA简化网格生成FE结构数据
         * @param    seaSubSys 子系统
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-01-15
         */
        bool genMeshSEASimplify(Acoustics::FITKAbstractSEASubSys* seaSubSys);
        /**
         * @brief    SEA细化网格生成FE结构数据
         * @param    seaSubSys 子系统
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-01-15
         */
        bool genMeshSEARefinement(Acoustics::FITKAbstractSEASubSys* seaSubSys);

    private:
        /**
         * @brief  ui object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-11-18
         */
        Ui::AutoGeneratedDialog* _ui = nullptr;
        /**
         * @brief 操作器对象
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-10-23
         */
        Core::FITKActionOperator* _oper = nullptr;
        /**
         * @brief  网格数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-12-26
         */
        Interface::FITKUnstructuredMesh* _meshObj{};
    };
    /**
     * @brief  geo脚本生成线程
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-01-15
     */
    class GeoScriptGenThread :public Core::FITKThreadTask
    {
        Q_OBJECT;
    public:
        /**
         * @brief Construct a new GeoScriptGenThread object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-23
         */
        GeoScriptGenThread(Acoustics::FITKAbstractSEASubSys* seaSubSys, Core::FITKActionOperator* oper);
        /**
         * @brief Destroy the GeoScriptGenThread object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-23
         */
        virtual ~GeoScriptGenThread() = default;
        /**
         * @brief 执行函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-23
         */
        void run();

    protected:
        /**
         * @brief    写出梁的geo脚本
         * @param[i] geoScriptFile 
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-01-15
         */
        bool writeBeamGeoScript(QString geoScriptFile);
        /**
         * @brief    写出板的geo脚本
         * @param[i] geoScriptFile
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-12-27
         */
        bool writeShellGeoScript(QString geoScriptFile);
        /**
         * @brief    写出声腔的geo脚本
         * @param[i] geoScriptFile 
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-01-15
         */
        bool writeCavityGeoScript(QString geoScriptFile);

    private:
        /**
         * @brief  SEA子系统
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-01-15
         */
        Acoustics::FITKAbstractSEASubSys* _seaSubSys{};
        /**
         * @brief  操作器
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-11-22
         */
        Core::FITKActionOperator* _oper{};
    };

    /**
     * @brief  简化网格线程
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2025-01-15
     */
    class SimplifyMeshThread :public Core::FITKThreadTask
    {
        Q_OBJECT;
    public:
        /**
         * @brief Construct a new SimplifyMeshThread object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-23
         */
        SimplifyMeshThread(Interface::FITKUnstructuredMesh* meshData, Acoustics::FITKAbstractSEASubSys* seaSubSys, Core::FITKActionOperator* oper);
        /**
         * @brief Destroy the SimplifyMeshThread object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-23
         */
        virtual ~SimplifyMeshThread() = default;
        /**
         * @brief 执行函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-23
         */
        void run();

    protected:
        /**
         * @brief    梁简化网格生成
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2025-01-15
         */
        bool beamMeshGen();
        /**
         * @brief    板简化网格生成
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-12-27
         */
        bool shellMeshGen();

    private:
        /**
         * @brief  SEA子系统
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2025-01-15
         */
        Acoustics::FITKAbstractSEASubSys* _seaSubSys{};
        /**
         * @brief  操作器
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-11-22
         */
        Core::FITKActionOperator* _oper{};
        /**
         * @brief  网格数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-12-26
         */
        Interface::FITKUnstructuredMesh* _meshObj{};
    };

}

#endif
